<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-L-admin1.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body class="layui-anim layui-anim-up">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
    <a class="layui-btn layui-btn-primary layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:38px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so">
            <input type="text" name="stuNo"  placeholder="请输入学生学号" id="stuNo" autocomplete="off" class="layui-input" style="width: 160px;">
            <input type="button" class="layui-btn" lay-submit="" lay-filter="search" id="searchByNo" value="搜索"
                   onclick="searchStuByNo()"/>
            <input type="text" name="stuName"  placeholder="请输入学生姓名" id="stuName" autocomplete="off" class="layui-input">
            <input type="button" class="layui-btn" lay-submit="" lay-filter="search" id="searchByName" value="搜索"
                   onclick="searchStuByName()"/>
            <input type="text" name="stuDl"  placeholder="请输入学生专业" id="stuDl" autocomplete="off" class="layui-input" style="width: 160px;">
            <input type="button" class="layui-btn" lay-submit="" lay-filter="search" id="searchByDis" value="搜索"
                   onclick="searchByDl()"/>
            <input type="text" name="stuGrade"  placeholder="请输入学生年级" id="stuGrade" autocomplete="off" class="layui-input"style="width: 140px;">
            <input type="button" class="layui-btn" lay-submit="" lay-filter="search" id="searchByGrade" value="搜索"
                   onclick="searchStuByGrade()"/>
            <br><br>
            <input type="button" class="layui-btn" id="showAll" onclick="showAllStu()" value="查看所有"/>
        </form>
    </div>
    <xblock>
<!--        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>-->
        <button class="layui-btn" onclick="x_admin_show('添加学生用户','./addStu.html',600,400)"><i class="layui-icon"></i>添加</button>
        <span class="x-right" style="line-height:40px">本次搜索总共搜索到<b><font size="4px" color="red" id="stuNum">这里填入搜索结果的统计数量</font></b>条数据</span>
    </xblock>

<!--    有时间的话可以增加一个功能让管理员锁定其他用户的修改自己信息的权限-->
    <table class="layui-table">
        <thead>
        <tr>
<!--            <th width="4%">-->
<!--                <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>-->
<!--            </th>-->
            <th>ID</th>
            <th>用户名</th>
            <th>密码</th>
            <th>专业</th>
            <th>年级</th>
            <th width="18%">操作</th>
        </tr>
        </thead>
        <tr id="student"></tr>
        <td id="button"></td>
        <tr id="student0">
            <td id="stuNo0"></td>
            <td id="stuName0"></td>
            <td id="stuPwd0"></td>
            <td id="stuDl0"></td>
            <td id="stuGrade0"></td>
            <td class="td-status" id="button0">
                <a  class="layui-btn layui-btn-sm layui-btn-warm" title="stu0" id="change"  onclick="x_admin_show_sendId(this.title,'changeStu.html',600,620)"  href="javascript:;">
                    修改个人信息
                </a>
                <a title="stu0" class="layui-btn layui-btn-sm layui-btn-danger" id="delete" onclick="member_del(this,this.title)" href="javascript:;">
                    删除用户
                </a>
            </td>
        </tr>
        <tbody id="studentList0">

        </tbody>
        <tbody id="studentList">

        </tbody>
    </table>


    <input id="Id" type="hidden" name="stuId" value="">
</div>

<script type="text/javascript">
    var manaNo=sessionStorage.getItem("manaNo");
    function showAllStu(){
    $.ajax({
        url: "/manager/getstulist",
        type : "post",
        async: false,
        dataType: "json",
        data : {manaNo:manaNo},
        // contentType: "application/json",
        success: function (data) {
            console.log("请求成功");
            var i=0;
            for (;;i++){
                if (data[i]){
                    if (i!==0){
                    var student=document.getElementById("student").cloneNode(true);
                    student.id="stu"+i;
                    var stuNo=document.getElementById("stuNo0").cloneNode(true);
                    var stuName=document.getElementById("stuName0").cloneNode(true);
                    var stuPwd=document.getElementById("stuPwd0").cloneNode(true);
                    var stuDl=document.getElementById("stuDl0").cloneNode(true);
                    var stuGrade=document.getElementById("stuGrade0").cloneNode(true);

                    stuNo.innerHTML=data[i].stuNo;
                    sessionStorage.setItem("stu"+i,data[i].stuNo);
                    stuName.innerHTML=data[i].stuName;
                    stuPwd.innerHTML=data[i].stuPwd;
                    stuDl.innerHTML=data[i].stuDiscipline;
                    stuGrade.innerHTML=data[i].stuGrade;

                    student.appendChild(stuNo);
                    student.appendChild(stuName);
                    student.appendChild(stuPwd);
                    student.appendChild(stuDl);
                    student.appendChild(stuGrade);

                    var button=document.getElementById("button").cloneNode(true);
                    var change=document.getElementById("change").cloneNode(true);
                    var del=document.getElementById("delete").cloneNode(true);
                    change.title="stu"+i;
                    del.title="stu"+i;

                    button.appendChild(change);
                    button.appendChild(del);
                    student.appendChild(button);

                    document.getElementById("studentList0").appendChild(student);
                    var j=i+1;
                    document.getElementById("stuNum").innerHTML=j;
                    }
                    else if (i==0){
                        sessionStorage.setItem('stu0',data[i].stuNo);

                        document.getElementById("stuNo0").innerHTML=data[0].stuNo;
                        document.getElementById("stuName0").innerHTML=data[0].stuName;
                        document.getElementById("stuPwd0").innerHTML=data[0].stuPwd;
                        document.getElementById("stuDl0").innerHTML=data[0].stuDiscipline;
                        document.getElementById("stuGrade0").innerHTML=data[0].stuGrade;
                    }
                }
                else break;
            }
            document.getElementById("studentList").innerHTML=null;
            for (i=1;;i++){
                if (data[i]){
                document.getElementById("studentList").appendChild(document.getElementById("stu"+i));
            }
        else break;
            }
            document.getElementById("studentList0").innerHTML=null;
        },
        error: function (data) {
            console.log("请求失败");
        }
    });
    }
    function searchStuByNo(){
        var id = $("#stuNo").val();

        $.ajax({
            url: "/student/getstubystuno",
            type : "post",
            async: false,
            dataType: "json",
            data : {stuNo:id},
            // contentType: "application/json",
            success: function (data) {
                console.log("请求成功");
                var i=0;
                for (;;i++){
                    if (data[i]){
                        if (i!==0){
                            var student=document.getElementById("student").cloneNode(true);
                            student.id="stu"+i;
                            var stuNo=document.getElementById("stuNo0").cloneNode(true);
                            var stuName=document.getElementById("stuName0").cloneNode(true);
                            var stuPwd=document.getElementById("stuPwd0").cloneNode(true);
                            var stuDl=document.getElementById("stuDl0").cloneNode(true);
                            var stuGrade=document.getElementById("stuGrade0").cloneNode(true);

                            stuNo.innerHTML=data[i].stuNo;
                            sessionStorage.setItem("stu"+i,data[i].stuNo);
                            stuName.innerHTML=data[i].stuName;
                            stuPwd.innerHTML=data[i].stuPwd;
                            stuDl.innerHTML=data[i].stuDiscipline;
                            stuGrade.innerHTML=data[i].stuGrade;

                            student.appendChild(stuNo);
                            student.appendChild(stuName);
                            student.appendChild(stuPwd);
                            student.appendChild(stuDl);
                            student.appendChild(stuGrade);

                            var button=document.getElementById("button").cloneNode(true);
                            var change=document.getElementById("change").cloneNode(true);
                            var del=document.getElementById("delete").cloneNode(true);
                            change.title="stu"+i;
                            del.title="stu"+i;

                            button.appendChild(change);
                            button.appendChild(del);
                            student.appendChild(button);

                            document.getElementById("studentList0").appendChild(student);
                            var j=i+1;
                            document.getElementById("stuNum").innerHTML=j;
                        }
                        else if (i==0){
                            sessionStorage.setItem('stu0',data[i].stuNo);

                            document.getElementById("stuNo0").innerHTML=data[0].stuNo;
                            document.getElementById("stuName0").innerHTML=data[0].stuName;
                            document.getElementById("stuPwd0").innerHTML=data[0].stuPwd;
                            document.getElementById("stuDl0").innerHTML=data[0].stuDiscipline;
                            document.getElementById("stuGrade0").innerHTML=data[0].stuGrade;
                        }
                    }
                    else break;
                }
                document.getElementById("studentList").innerHTML=null;
                for (i=1;;i++){
                    if (data[i]){
                        document.getElementById("studentList").appendChild(document.getElementById("stu"+i));
                    }
                    else break;
                }
                document.getElementById("studentList0").innerHTML=null;
            },
            error: function (data) {
                console.log("请求失败");
            }
        });
    }
    function searchStuByName(){
        var name = $("#stuName").val();
        console.log(name);
        $.ajax({
            url: "/student/getstubystuname",
            type : "post",
            async: false,
            dataType: "json",
            data : {stuName:name},
            // contentType: "application/json",
            success: function (data) {
                console.log("请求成功");
                var i=0;
                for (;;i++){
                    if (data[i]){
                        if (i!==0){
                            var student=document.getElementById("student").cloneNode(true);
                            student.id="stu"+i;
                            var stuNo=document.getElementById("stuNo0").cloneNode(true);
                            var stuName=document.getElementById("stuName0").cloneNode(true);
                            var stuPwd=document.getElementById("stuPwd0").cloneNode(true);
                            var stuDl=document.getElementById("stuDl0").cloneNode(true);
                            var stuGrade=document.getElementById("stuGrade0").cloneNode(true);

                            stuNo.innerHTML=data[i].stuNo;
                            sessionStorage.setItem("stu"+i,data[i].stuNo);
                            stuName.innerHTML=data[i].stuName;
                            stuPwd.innerHTML=data[i].stuPwd;
                            stuDl.innerHTML=data[i].stuDiscipline;
                            stuGrade.innerHTML=data[i].stuGrade;

                            student.appendChild(stuNo);
                            student.appendChild(stuName);
                            student.appendChild(stuPwd);
                            student.appendChild(stuDl);
                            student.appendChild(stuGrade);

                            var button=document.getElementById("button").cloneNode(true);
                            var change=document.getElementById("change").cloneNode(true);
                            var del=document.getElementById("delete").cloneNode(true);
                            change.title="stu"+i;
                            del.title="stu"+i;

                            button.appendChild(change);
                            button.appendChild(del);
                            student.appendChild(button);

                            document.getElementById("studentList0").appendChild(student);
                            var j=i+1;
                            document.getElementById("stuNum").innerHTML=j;
                        }
                        else if (i==0){
                            sessionStorage.setItem('stu0',data[i].stuNo);

                            document.getElementById("stuNo0").innerHTML=data[0].stuNo;
                            document.getElementById("stuName0").innerHTML=data[0].stuName;
                            document.getElementById("stuPwd0").innerHTML=data[0].stuPwd;
                            document.getElementById("stuDl0").innerHTML=data[0].stuDiscipline;
                            document.getElementById("stuGrade0").innerHTML=data[0].stuGrade;
                            document.getElementById("stuNum").innerHTML=1;
                        }
                    }
                    else break;
                }
                document.getElementById("studentList").innerHTML=null;
                for (i=1;;i++){
                    if (data[i]){
                        document.getElementById("studentList").appendChild(document.getElementById("stu"+i));
                    }
                    else break;
                }
                document.getElementById("studentList0").innerHTML=null;
            },
            error: function (data) {
                console.log("请求失败");
            }
        });
    }
    function searchByDl(){
        var dl = $("#stuDl").val();

        $.ajax({
            url: "/student/getstubystudis",
            type : "post",
            async: false,
            dataType: "json",
            data : {stuDiscipline:dl},
            // contentType: "application/json",
            success: function (data) {
                console.log("请求成功");
                var i=0;
                for (;;i++){
                    if (data[i]){
                        if (i!==0){
                            var student=document.getElementById("student").cloneNode(true);
                            student.id="stu"+i;
                            var stuNo=document.getElementById("stuNo0").cloneNode(true);
                            var stuName=document.getElementById("stuName0").cloneNode(true);
                            var stuPwd=document.getElementById("stuPwd0").cloneNode(true);
                            var stuDl=document.getElementById("stuDl0").cloneNode(true);
                            var stuGrade=document.getElementById("stuGrade0").cloneNode(true);

                            stuNo.innerHTML=data[i].stuNo;
                            sessionStorage.setItem("stu"+i,data[i].stuNo);
                            stuName.innerHTML=data[i].stuName;
                            stuPwd.innerHTML=data[i].stuPwd;
                            stuDl.innerHTML=data[i].stuDiscipline;
                            stuGrade.innerHTML=data[i].stuGrade;

                            student.appendChild(stuNo);
                            student.appendChild(stuName);
                            student.appendChild(stuPwd);
                            student.appendChild(stuDl);
                            student.appendChild(stuGrade);

                            var button=document.getElementById("button").cloneNode(true);
                            var change=document.getElementById("change").cloneNode(true);
                            var del=document.getElementById("delete").cloneNode(true);
                            change.title="stu"+i;
                            del.title="stu"+i;

                            button.appendChild(change);
                            button.appendChild(del);
                            student.appendChild(button);

                            document.getElementById("studentList0").appendChild(student);
                            var j=i+1;
                            document.getElementById("stuNum").innerHTML=j;
                        }
                        else if (i==0){
                            sessionStorage.setItem('stu0',data[i].stuNo);

                            document.getElementById("stuNo0").innerHTML=data[0].stuNo;
                            document.getElementById("stuName0").innerHTML=data[0].stuName;
                            document.getElementById("stuPwd0").innerHTML=data[0].stuPwd;
                            document.getElementById("stuDl0").innerHTML=data[0].stuDiscipline;
                            document.getElementById("stuGrade0").innerHTML=data[0].stuGrade;
                        }
                    }
                    else break;
                }
                document.getElementById("studentList").innerHTML=null;
                for (i=1;;i++){
                    if (data[i]){
                        document.getElementById("studentList").appendChild(document.getElementById("stu"+i));
                    }
                    else break;
                }
                document.getElementById("studentList0").innerHTML=null;
            },
            error: function (data) {
                console.log("请求失败");
            }
        });
    }
    function searchStuByGrade(){
        var grade = $("#stuGrade").val();

        $.ajax({
            url: "/student/getstubystugrade",
            type : "post",
            async: false,
            dataType: "json",
            data : {stuGrade:grade},
            // contentType: "application/json",
            success: function (data) {
                console.log("请求成功");
                var i=0;
                for (;;i++){
                    if (data[i]){
                        if (i!==0){
                            var student=document.getElementById("student").cloneNode(true);
                            student.id="stu"+i;
                            var stuNo=document.getElementById("stuNo0").cloneNode(true);
                            var stuName=document.getElementById("stuName0").cloneNode(true);
                            var stuPwd=document.getElementById("stuPwd0").cloneNode(true);
                            var stuDl=document.getElementById("stuDl0").cloneNode(true);
                            var stuGrade=document.getElementById("stuGrade0").cloneNode(true);

                            stuNo.innerHTML=data[i].stuNo;
                            sessionStorage.setItem("stu"+i,data[i].stuNo);
                            stuName.innerHTML=data[i].stuName;
                            stuPwd.innerHTML=data[i].stuPwd;
                            stuDl.innerHTML=data[i].stuDiscipline;
                            stuGrade.innerHTML=data[i].stuGrade;

                            student.appendChild(stuNo);
                            student.appendChild(stuName);
                            student.appendChild(stuPwd);
                            student.appendChild(stuDl);
                            student.appendChild(stuGrade);

                            var button=document.getElementById("button").cloneNode(true);
                            var change=document.getElementById("change").cloneNode(true);
                            var del=document.getElementById("delete").cloneNode(true);
                            change.title="stu"+i;
                            del.title="stu"+i;

                            button.appendChild(change);
                            button.appendChild(del);
                            student.appendChild(button);

                            document.getElementById("studentList0").appendChild(student);
                            var j=i+1;
                            document.getElementById("stuNum").innerHTML=j;
                        }
                        else if (i==0){
                            sessionStorage.setItem('stu0',data[i].stuNo);
                            document.getElementById("stuNum").innerHTML=1;
                            document.getElementById("stuNo0").innerHTML=data[0].stuNo;
                            document.getElementById("stuName0").innerHTML=data[0].stuName;
                            document.getElementById("stuPwd0").innerHTML=data[0].stuPwd;
                            document.getElementById("stuDl0").innerHTML=data[0].stuDiscipline;
                            document.getElementById("stuGrade0").innerHTML=data[0].stuGrade;
                        }
                    }
                    else break;
                }
                document.getElementById("studentList").innerHTML=null;
                for (i=1;;i++){
                    if (data[i]){
                        document.getElementById("studentList").appendChild(document.getElementById("stu"+i));
                    }
                    else break;
                }
                document.getElementById("studentList0").innerHTML=null;
            },
            error: function (data) {
                console.log("请求失败");
            }
        });
    }
</script>

<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });



    /*用户-删除*/
    function member_del(obj,s){
        console.log(s);
            var stuNo=sessionStorage.getItem(s);
            console.log(stuNo);

            $.ajax({
                url: "/manager/deletestu",
                type : "post",
                async: false,
                dataType: "json",
                data : {stuNo:stuNo},

                success: function (data) {
                    console.log('请求成功');
                    if (data==1){
                    $(obj).parents("tr").remove();
                    alert("删除成功");}
                    else alert("删除失败");
                },
                error: function (data) {
                    console.log("请求失败");
                }
            });




    }




</script>
</body>

</html>